package com.iflysse.vo;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.iflysse.consts.ResultEnum;

/**
 * 对响应的结果通用封装
 * 
 * @author oubijie
 *
 */
public class AjaxResult {

	private int code;
	private String msg;

	@JsonInclude(value = Include.NON_NULL)
	private Object result;
	private String version = "1.0";

	/**
	 * 执行insert、update和delete时，根据成功的记录条数生成响应的JSON
	 * 
	 * @param success 成功的记录条数
	 */
	public static AjaxResult getResultBySuccess(int success) {
		if (success < 1) {
			return new AjaxResult(ResultEnum.NOTSUCCESS.getCode(), ResultEnum.NOTSUCCESS.getMsg());
		} else {
			return new AjaxResult(ResultEnum.SUCCESS.getCode(), ResultEnum.SUCCESS.getMsg());
		}
	}

	public static AjaxResult success(Object result) {
		return new AjaxResult(ResultEnum.SUCCESS.getCode(), ResultEnum.SUCCESS.getMsg(), result);
	}

	public AjaxResult() {
	}

	public AjaxResult(int code, String msg) {
		this.code = code;
		this.msg = msg;
	}

	public AjaxResult(int code, String msg, Object result) {
		this.code = code;
		this.msg = msg;
		this.result = result;
	}

	public int getCode() {
		return code;
	}

	public void setCode(int code) {
		this.code = code;
	}

	public String getMsg() {
		return msg;
	}

	public void setMsg(String msg) {
		this.msg = msg;
	}

	public Object getResult() {
		return result;
	}

	public void setResult(Object result) {
		this.result = result;
	}

	public String getVersion() {
		return version;
	}

	public void setVersion(String version) {
		this.version = version;
	}

}
